import dateFormat from "vux/src/tools/date/format.js";

import { mapGetters } from "vuex";
import { addClass, removeClass } from "@/assets/js/dom.js";
import dataTimeFilter from "../../../common/dataTimeFilter/dataTimeFilter";
import template from "./agencyTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  components: {
    dataTimeFilter,
  },
  data() {
    return {
      datePicker: false,
      pikerShow: false,
      beginTime: dateFormat(new Date(), "YYYY-MM-DD"),
      endTime: dateFormat(new Date(), "YYYY-MM-DD"),

      dataList: [],

      userTypeList: [
        { id: 1, name: "代理+直属" },
        { id: 2, name: "代理+团队" },
      ],
      nowId: 1,
      userType: 1,
      userValue: "代理+直属",
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  created() {
    this.resetAll();
  },
  methods: {
    activeCopy(e) {
      addClass(e.target, "activeScroll");
      document.addEventListener("touchmove", () => {
        removeClass(e.target, "activeScroll");
      });
      document.addEventListener("touchend", () => {
        removeClass(e.target, "activeScroll");
      });
    },
    pullingDown() {
      this._getDataList();
    },
    resetAll() {
      let vm = this;
      vm.userType = 1;
      vm.userValue = "代理+直属";
      vm.beginTime = "";
      vm.endTime = "";
      vm.nowId = 1;
      vm._getDataList(1);
    },
    pickHide(data) {
      this.datePicker = data;
    },
    getTime(data) {
      this.beginTime = data[0];
      this.endTime = data[1];
      this.datePicker = false;

      this._getDataList(1);
    },
    picking(id) {
      this.nowId = id;
      this.userType = id;
      this.userValue = this.userTypeList.find((item) => {
        return item.id == id;
      }).name;

      setTimeout(() => {
        this.pikerShow = false;
      }, 200);
      this._getDataList(1);
    },
    _getDataList(flag) {
      let vm = this;
      if (flag) {
        vm.$vux.loading.show();
      }
      let params = {};
      params.token = localStorage.getItem("token");
      params.start_time = vm.beginTime;
      params.end_time = vm.endTime;
      params.user_type = vm.userType;
      vm.$http
        .post(vm.urlRequest + "?m=api&c=user&a=agentReportForms", params)
        .then((res) => {
          if (res.status == 0) {
            vm.dataList = res;
          } else {
            if (res.ret_msg && res.ret_msg != "") {
              vm.$vux.toast.show({
                text: res.ret_msg,
              });
            }
          }
          vm.$refs.scroll.forceUpdate(false);
          vm.$vux.loading.hide();
        })
        .catch((err) => {
          vm.$vux.loading.hide();
          vm.$refs.scroll.forceUpdate(false);
          console.log(err);
        });
    },
  },
  watch: {},
};

// WEBPACK FOOTER //
// ./src/components/personalCenter/teamManagement/agency/agency.vue
